import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.*;

/*
 ID: ning yusui
 LANG: JAVA
 TASK: runround
 */

public class runround {
	

	private static boolean isRunround(int num) {
		final String strNum = String.valueOf(num);
		boolean[] visit = new boolean[11];
		visit[0]=true;
		for (int i = 1; i < visit.length; i++) {
			visit[i] = false;
		}

		int length = strNum.length();
		for (int i = 0; i < length; i++) {
			int digit = (strNum.charAt(i) - '0');
			if (visit[digit]) {
				return false;
			}
			visit[digit] = true;
		}

		for (int i = 0; i < visit.length; i++) {
			visit[i] = false;
		}

		int nextIndex = 0;
		String retString="";
		for (int i = 0; i < length; i++) {
			int digit = (strNum.charAt(nextIndex) - '0');
			nextIndex = (nextIndex + digit) % length;
			retString=retString+digit;
			if (visit[nextIndex]) {
				return false;
			}
			visit[nextIndex] = true;
		}

		return true;
	}

	public static void main(String[] args) throws IOException {
		Scanner in = new Scanner(new File("runround.in"));
		PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(
				"runround.out")));
		int n = in.nextInt();
		for (;n++>0;) {
			if (isRunround(n)) {
				out.println(n);
				break;
			}
		}
		out.close();
	}
}
